---
title: "Tidy Tuesday 2019 week 43: Oh the horror"
output:
flexdashboard::flex_dashboard:
navbar:
- { title: home,
href: "https://github.com/k-maciejewski/TidyTuesdays/",
align: right}
- { icon: fa-github-square,
href: "https://github.com/k-maciejewski/TidyTuesdays/",
align: right }
orientation: columns
vertical_layout: scroll
source_code: embed
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F)
library(flexdashboard)
library(tidyverse)
library(maps)
library(plotly)
library(viridis)
```
```{r load_data}
horror_movies <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-10-22/horror_movies.csv")
```
```{r data_manipulation}
horror <- horror_movies %>% mutate(id = row_number()) %>%
separate_rows(genres, sep = "\\| ") %>%
mutate(y = 1) %>%
spread(genres, y, fill = 0)
horror$filming_country <- gsub(".*, ", "", horror$filming_locations)
worldmap <- map_data("world") %>% tbl_df %>% filter(region !="Antarctica")
```
About {.sidebar}
-------------------------------------
For my first Tidy Tuesday, I explored the [dataset of horror movies](https://github.com/rfordatascience/tidytuesday/tree/master/data/2019/2019-10-22) from the IMDB Horror Movie Dataset at [Kaggle](https://www.kaggle.com/PromptCloudHQ/imdb-horror-movie-dataset). I'm not a huge horror fan, but when I saw location data, I knew what I would do: practice my mapping! Even though I didn't use it, changing the strings of genres to indicator functions was also good practice.
```{r}
g_film <- horror %>%
group_by(filming_country) %>%
summarise(total = n()) %>%
top_n(., 5)
g_film[order(-g_film$total),] %>% knitr::kable()
g1 <- horror %>%
group_by(release_country) %>%
summarise(total = n()) %>%
top_n(., 5)
g1[order(-g1$total),] %>% knitr::kable()
g2<-horror %>%
group_by(release_country) %>%
summarise(average = mean(review_rating, na.rm = T)) %>%
top_n(., 5)
g2[order(-g2$average),] %>% knitr::kable()
```
column
-----------------------------------------------------
### Horror movie filming location in each country from 2012 to 2017
```{r}
g_film <- horror %>%
group_by(filming_country) %>%
summarise(total = n()) %>%
right_join(worldmap, by = c("filming_country" = "region")) %>%
ggplot(aes(long, lat, group = group, fill = total)) +
geom_polygon(color = "black") +
scale_fill_gradient(low = "darkolivegreen1", high = "darkolivegreen", na.value = "grey80") +
theme(axis.text = element_blank(),
axis.title = element_blank()) +
labs(title = "")
ggplotly(g_film)
```
### Horror movies released by country from 2012 to 2017
```{r}
g_release <- horror %>%
group_by(release_country) %>%
summarise(total = n()) %>%
right_join(worldmap, by = c("release_country" = "region")) %>%
ggplot(aes(long, lat, group = group, fill = total)) +
geom_polygon(color = "black") +
scale_fill_viridis(na.value = "grey80") +
theme(axis.text = element_blank(),
axis.title = element_blank()) +
labs(title = "")
ggplotly(g_release)
```
### Average horror movie ratings in each country from 2012 to 2017
```{r}
g_star <- horror %>%
group_by(release_country) %>%
summarise(average = mean(review_rating, na.rm = T)) %>%
right_join(worldmap, by = c("release_country" = "region")) %>%
ggplot(aes(long, lat, group = group, fill = average)) +
geom_polygon(color = "black") +
scale_fill_gradient(low = "red", high = "yellow", na.value = "grey80") +
theme(axis.text = element_blank(),
axis.title = element_blank()) +
labs(title = "")
ggplotly(g_star)
```